﻿package mortal.game.scene3D.display3d.icon3d
{
    import baseEngine.basic.*;
    import com.gengine.resource.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.game.scene3D.*;
    import mortal.game.scene3D.layer3D.*;
    import mortal.game.scene3D.player.head.*;

    public class Icon3DFactory extends Object
    {
        private var _scene:GameScene3D;
        private var renderListDic:Dictionary;
        private var _bigImgList:Dictionary;
        private var _iconsList:Object;
        public static const instance:Icon3DFactory = new Icon3DFactory;

        public function Icon3DFactory()
        {
            this.renderListDic = new Dictionary(false);
            this._bigImgList = new Dictionary(false);
            return;
        }// end function

        public function config() : void
        {
            var _loc_1:* = ConfigManager.instance.getByteArrayByFileName("iconObject.vas");
            this._iconsList = _loc_1.readObject();
            return;
        }// end function

        public function checkToDispose(event:Event = null) : void
        {
            var _loc_4:Icon3DBigImg = null;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_2:* = getTimer();
            var _loc_3:* = new Array();
            for each (_loc_4 in this._bigImgList)
            {
                
                if (_loc_4.canDispose(_loc_2))
                {
                    _loc_3.push(_loc_4);
                }
            }
            _loc_5 = _loc_3.length;
            _loc_6 = 0;
            while (_loc_6 < _loc_5)
            {
                
                _loc_4 = _loc_3[_loc_6];
                _loc_4.disposeAll();
                delete this._bigImgList[_loc_4.url];
                _loc_6++;
            }
            return;
        }// end function

        public function init(param1:GameScene3D) : void
        {
            var _loc_2:Icon3DBigImg = null;
            this._scene = param1;
            this.setRenderList("otherIcons2.png", LastRender.instance.renderList);
            Icon3DRender.instance.init(param1);
            for each (_loc_2 in this._bigImgList)
            {
                
                _loc_2.init(this._scene);
            }
            return;
        }// end function

        public function reinit(param1:GameScene3D) : void
        {
            var _loc_2:Icon3DBigImg = null;
            Icon3DRender.instance.reinit(param1);
            for each (_loc_2 in this._bigImgList)
            {
                
                _loc_2.reinit(this._scene);
            }
            return;
        }// end function

        public function sort(param1:Icon3D, param2:Icon3D) : Boolean
        {
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_7:Number = NaN;
            var _loc_8:Number = NaN;
            if (!param1 || !param2 || param1.bigImgUrl != param2.bigImgUrl)
            {
                return false;
            }
            if (param1._ix < param2._ix)
            {
                _loc_3 = param1.xx;
                _loc_4 = param1.yy;
                _loc_5 = param1.xNum;
                _loc_6 = param1.yNum;
                param1.setImgPos(param2.xx, param2.yy, param2.xNum, param2.yNum);
                param2.setImgPos(_loc_3, _loc_4, _loc_5, _loc_6);
                _loc_7 = param1.x;
                _loc_8 = param1.y;
                param1.x = param2.x;
                param1.y = param2.y;
                param2.x = _loc_7;
                param2.y = _loc_8;
                return true;
            }
            return false;
        }// end function

        public function geticonId(param1:String) : String
        {
            return this._iconsList[param1];
        }// end function

        public function createOtherIcon3D(param1:String, param2:OtherIconInfo) : Icon3D
        {
            return this.createicon3D(param1, param2.x, param2.y, param2.xNum, param2.yNum);
        }// end function

        public function createicon3D(param1:String, param2:uint, param3:uint, param4:int, param5:int) : Icon3D
        {
            var _loc_6:* = this._bigImgList[param1];
            if (_loc_6 == null)
            {
                var _loc_7:* = new Icon3DBigImg(param1, this.renderListDic[param1]);
                _loc_6 = new Icon3DBigImg(param1, this.renderListDic[param1]);
                this._bigImgList[param1] = _loc_7;
                if (this._scene)
                {
                    _loc_6.init(this._scene);
                }
            }
            return _loc_6.createIcon3D(param2, param3, param4, param5);
        }// end function

        public function setRenderList(param1:String, param2:RenderList) : void
        {
            this.renderListDic[param1] = param2;
            var _loc_3:* = this._bigImgList[param1];
            if (_loc_3)
            {
                _loc_3.setRenderList(param2);
            }
            return;
        }// end function

        public function disposeIcon3D(param1:Icon3D) : void
        {
            if (param1.parent)
            {
                param1.parent = null;
            }
            var _loc_2:* = this._bigImgList[param1.bigImgUrl];
            if (_loc_2)
            {
                _loc_2.disposeIcon3D(param1);
            }
            return;
        }// end function

    }
}
